home *** CD-ROM | disk | FTP | other *** search
- // ==================================================
- // UDateTime.cp
- // Copyright (C) 1994-96 Mizutori Tetsuya, March 9 1994, July 4 1996.
- // ==================================================
- // All documents are pretty-printed in Geneva 10-point font.
-
- #include <TextUtils.h>
- #include <Script.h>
- #include <IntlResources.h>
- #include <OSUtils.h>
-
- #include <UMemoryMgr.h>
- #include <UDebugging.h>
-
- #include "UDateTime.h"
-
- #define longDateTimeHi( a ) (((LongDateCvt *) &(a))->hl.lHigh)
- #define longDateTimeLo( a ) (((LongDateCvt *) &(a))->hl.lLow)
-
-
- #define kWantSeconds true
- #define k_intl_NumericFormat 0
- #define k_intl_LongDateFormat 1
-
-
- // --------------------------------------------------
- // ・ SecondsToDateTimeString
- // --------------------------------------------------
-
- void
- UDateTime::SecondsToDateTimeString(
- const unsigned long inSeconds,
- Str255 outDateString,
- Str255 outTimeString )
- {
- LongDateRec theDateTime;
-
- SecondsToDateTime( inSeconds, theDateTime );
-
- DateTimeToString( theDateTime, outDateString, outTimeString );
- }
-
-
- // --------------------------------------------------
- // ・ DateTimeStringToSeconds
- // --------------------------------------------------
-
- void
- UDateTime::DateTimeStringToSeconds(
- const Str255 inDateString,
- const Str255 inTimeString,
- unsigned long & outSeconds )
- {
- LongDateRec theDateTime;
-
- StringToDateTime( inDateString, inTimeString, theDateTime );
-
- DateTimeToSeconds( theDateTime, outSeconds );
- }
-
-
- // --------------------------------------------------
- // ・ SecondsToDateTime
- // --------------------------------------------------
-
- void
- UDateTime::SecondsToDateTime(
- const unsigned long inSeconds,
- LongDateRec & outDateTime )
- {
- LongDateTime theDateTimeSecs;
-
- longDateTimeHi( theDateTimeSecs ) = 0;
- longDateTimeLo( theDateTimeSecs ) = inSeconds;
-
- ::LongSecondsToDate( &theDateTimeSecs, &outDateTime );
- }
-
-
- // --------------------------------------------------
- // ・ DateTimeToSeconds
- // --------------------------------------------------
-
- void
- UDateTime::DateTimeToSeconds(
- const LongDateRec & inDateTime,
- unsigned long & outSeconds )
- {
- LongDateTime theDateTimeSecs;
-
- LongDateToSeconds( &inDateTime, &theDateTimeSecs );
-
- outSeconds = longDateTimeLo( theDateTimeSecs );
- }
-
-
- // --------------------------------------------------
- // ・ DateTimeToString
- // --------------------------------------------------
-
- void
- UDateTime::DateTimeToString(
- const LongDateRec & inDateTime,
- Str255 outDateString,
- Str255 outTimeString )
- {
- LongDateTime theDateTimeSecs;
- LongDateToSeconds( &inDateTime, &theDateTimeSecs );
-
- Handle intlH;
- Size theSize;
- intlH = ::GetIntlResource( k_intl_NumericFormat ); // as 'Intl0Rec'
- theSize = ::GetHandleSize( intlH );
-
- StClearHandleBlock theIntlH( theSize, true );
- ::BlockMoveData( *intlH, *theIntlH, theSize );
-
- // ((Intl0Ptr)*theIntlH)->dateOrder = mdy; // m/d/y order
- // ((Intl0Ptr)*theIntlH)->shrtDateFmt = century; // include century
- // ((Intl0Ptr)*theIntlH)->shrtDateFmt |= mntLdingZ; // lead 0 for month
- // ((Intl0Ptr)*theIntlH)->shrtDateFmt |= dayLdingZ; // lead 0 for day
- // ((Intl0Ptr)*theIntlH)->shrtDateFmt &= ~century; // suppress century
- // ((Intl0Ptr)*theIntlH)->dateSep = '/'; // date separator
-
- ::LongDateString( &theDateTimeSecs, shortDate, outDateString, theIntlH );
-
- ((Intl0Ptr)*theIntlH)->timeCycle = timeCycle24; // or; timeCycleZero, timeCycle12
- ((Intl0Ptr)*theIntlH)->timeFmt |= secLeadingZ | minLeadingZ | hrLeadingZ;
- // ((Intl0Ptr)*theIntlH)->timeSep = ':'; // time separator
-
- ::LongTimeString( &theDateTimeSecs, kWantSeconds, outTimeString, theIntlH );
- }
-
-
- // --------------------------------------------------
- // ・ StringToDateTime
- // --------------------------------------------------
-
- void
- UDateTime::StringToDateTime(
- const Str255 inDateString,
- const Str255 inTimeString,
- LongDateRec & outDateTime )
- {
- Size lengthUsed;
- DateCacheRecord theCache;
- StringToDateStatus stdStatus;
-
- ::InitDateCache( &theCache );
-
- stdStatus = ::StringToDate( (Ptr) &inDateString[1], inDateString[0],
- &theCache, &lengthUsed, &outDateTime );
- stdStatus = ::StringToTime( (Ptr) &inTimeString[1], inTimeString[0],
- &theCache, &lengthUsed, &outDateTime );
- }
-
-
- // end of program
-